package cmd

import (
	"fmt"
	"os"

	"gitee.com/eeppee_admin/go-tuiftp/reuse"
	"github.com/spf13/cobra"
)

// 根命令
func NewCommand() *cobra.Command {
	cmd := &cobra.Command{
		// 使用方式
		Use: reuse.AppName + " " + reuse.AppVersion,
		// 短描述
		Short: "ftp cli client | ftp cli客户端",
		// 长描述
		Long: reuse.AppName + " license with MIT",
		// 回调
		Run: func(cmd *cobra.Command, args []string) {
			if err := cmd.Help(); err != nil {
				// errors met
				fmt.Println("error: help command error, ", err)
				os.Exit(-1)
			}
		},
	}

	// 子命令
	cmd.AddCommand(NewConfigCommand())
	cmd.AddCommand(GenericNewCommand("ls", "list dir", "列出目录", &LsOperation{}))
	cmd.AddCommand(GenericNewCommand("cp", "copy file", "复制文件", &CpOperation{}))
	cmd.AddCommand(GenericNewCommand("rm", "remove file", "删除文件", &RmOperation{}))
	cmd.AddCommand(GenericNewCommand("rls", "recursive list dir", "递归列出目录", &RLsOperation{}))
	// todo: 实验性支持tui list
	cmd.AddCommand(GenericNewCommand("tls", "tui ls", "交互式显示文件列表", &TLsOperation{}))
	// todo: add more command here
	return cmd
}
